package com.aiyige.utils;

import android.text.TextUtils;

import com.aiyige.arouter.config.ARouterConfig;
import com.aiyige.page.photo.model.Photo;
import com.aiyige.page.photo.model.PhotoDetail;
import com.alibaba.android.arouter.launcher.ARouter;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by xiachao
 */

public class PhotoUtil {

    /**
     * 图片浏览（多个）
     * 无title
     *
     * @param
     */
    public static void startPhotoView(List<String> photos) {
        if (ListUtil.isEmpty(photos)) {
            return;
        }
        boolean isWebUrl = false;
        String firstImageUrl = ListUtil.getFirstItem(photos);
        if (!TextUtils.isEmpty(firstImageUrl) && firstImageUrl.trim().startsWith("http")) {
            isWebUrl = true;
        }
        List<Photo> photoList = new LinkedList<>();
        for (String imageUrl : photos) {
            photoList.add(Photo.newBuilder()
                    .url(imageUrl)
                    .introduction("")
                    .build());
        }
        PhotoDetail photoDetail = PhotoDetail.newBuilder()
                .localPhoto(!isWebUrl)
                .playIndex(0)
                .photoList(photoList)
                .build();
        ARouter.getInstance()
                .build(ARouterConfig.PhotoPage)
                .withParcelable("photoDetail", photoDetail)
                .navigation();
    }

    /**
     * 图片浏览(单个)
     * 无title
     *
     * @param
     */
    public static void startPhotoView(String photo) {
        if (TextUtils.isEmpty(photo)) {
            return;
        }
        startPhotoView(Arrays.asList(photo));
    }


}
